package com.isunland.managesystem.ui;

import com.google.gson.Gson;
import com.isunland.managesystem.base.BaseNetworkDialogFragment;
import com.isunland.managesystem.common.ApiConst;
import com.isunland.managesystem.common.MyConst;
import com.isunland.managesystem.entity.CurrentUser;
import com.isunland.managesystem.entity.CustomerDialog;
import com.isunland.managesystem.entity.SysOrg;
import com.isunland.managesystem.entity.SysOrgListOriginal;
import com.isunland.managesystem.utils.ParamsNotEmpty;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * 对象功能:获取下级组织机构列表
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: wangyanan
 * 创建时间: 2017/4/26 18:20
 */
public class SysOrgBelongDialogFragment extends BaseNetworkDialogFragment {

  @Override public ArrayList<CustomerDialog> resolveResponse(String arg0) {
    ArrayList<CustomerDialog> list = new ArrayList<>();
    SysOrgListOriginal original = new Gson().fromJson(arg0, SysOrgListOriginal.class);
    ArrayList<SysOrg> rows = original.getRows();
    if (rows == null || rows.size() == 0) {

      return null;
    }
    for (int i = 0; i < rows.size(); i++) {
      list.add(new CustomerDialog(rows.get(i).getOrgName(), rows.get(i).getOrgCode()));
    }
    return list;
  }

  @Override public String getUrl() {
    return ApiConst.URL_QUERY_LIST_SYSORG_BELONG;
  }

  @Override public HashMap<String, String> getparameters() {
    ParamsNotEmpty params = new ParamsNotEmpty();
    params.put("memberCode", CurrentUser.newInstance(getActivity()).getMemberCode());
    params.put("ifWithBelong", MyConst.TRUE);
    params.put("app", MyConst.TRUE);
    return params.getParams();
  }
}
